package com.ruoyi.common.utils.file;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class DxfDownLoadUtils {
    public static String getDxf(MultipartFile multipartFile){
        if (!multipartFile.getOriginalFilename().endsWith(".dxf")) {
            return "文件类型不正确";
        }

        // 保存文件
        String desktopPath = System.getProperty("user.home") + "/Desktop/";
        String filePath = desktopPath + multipartFile.getOriginalFilename();

        try (FileOutputStream fos = new FileOutputStream(new File(filePath));){

            fos.write(multipartFile.getBytes());
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
            return "文件保存失败";
        }

        // 返回文件地址
        return "文件已保存至: " + filePath;
    }
}
